package lion.dev.text;

import java.util.Date;

import org.apache.commons.lang.time.DateUtils;

/**
 * @author lion
 * @mail hl_0074@sina.com
 * @date 2011-10-16
 * 
 */
public class TimeUtil {

	public static String diffTimeString(Date dateStart, Date dateEnd) {

		long diff = (dateEnd.getTime() - dateStart.getTime());

		if (diff < 1000) { return "刚刚"; }

		if (diff < DateUtils.MILLIS_PER_MINUTE) {
			return diff / 1000 + "秒前";
		} else if (diff < DateUtils.MILLIS_PER_HOUR) {
			return (diff / DateUtils.MILLIS_PER_MINUTE) + "分钟前";
		} else if (diff < DateUtils.MILLIS_PER_DAY) {
			return (diff / DateUtils.MILLIS_PER_HOUR) + "小时前";
		} else if (diff / DateUtils.MILLIS_PER_DAY < 3) {
			return (diff / DateUtils.MILLIS_PER_DAY) + "天前";
		} else {
			return Formater.formatDate("yyyy-MM-dd HH:mm:ss", dateStart);
		}
	}
}
